home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / REFERENC / TPR / SOURCE.EXE / FSEARCH.PAS < prev    next >
Pascal/Delphi Source File  |  1992-08-07  |  1KB  |  51 lines

  1. { FSEARCH.PAS }
  2. Program DemoSearch;
  3. { Demonstrates an algorithm to locate a program's required data and
  4.   configuration files through the use of the DosVersion function,
  5.   ParamStr function, FSplit procedure and FSearch function.  This algorithm
  6.   assumes that the required config. files are kept in the same directory
  7.   as the .EXE file.
  8. }
  9. uses
  10.   Dos;
  11.  
  12. const
  13.   { This is the filename that we must locate }
  14.   DataFilename = 'SCRATCH.DAT';
  15.  
  16. var
  17.   Path : PathStr;
  18.   Directory : DirStr;
  19.   FName : NameStr;
  20.   Extension : ExtStr;
  21.   F : File;
  22.  
  23. begin
  24.  
  25.   Path := '';
  26.   {$I-}
  27.   { First, check the current directory }
  28.   Assign( F, DataFilename );
  29.   Reset( F );
  30.   if IoResult <> 0 then
  31.   { if not found here, then continue checking ... }
  32.   begin
  33.     if Lo(DosVersion) >= 3.0 then
  34.     { if running >= DOS 3.0, then use ParamStr(0) to get location of
  35.       the .EXE file and assume that directory for the data files }
  36.     begin
  37.       FSplit ( ParamStr(0), Directory, FName, Extension );
  38.       Path := Directory;
  39.     end
  40.     else
  41.       { Otherwise, search through the list of directories in the DOS
  42.         PATH statement.  The .EXE, and hence, its data files, must
  43.         have been booted from one of these directories. }
  44.       Path := FSearch ( DataFileName, GetEnv('PATH') );
  45.   end
  46.   else
  47.   Close ( F );
  48.  
  49.   Writeln('Path = ', Path );
  50. end.
  51.